
///
/// This is the Server class
///

#ifndef SERVER_H
#define SERVER_H

#include "timer.h"
#include "common.h"
#include "Handler.h"
#include <map>

#define BACKLOG 10

typedef std::map<int, std::pair<timer , Handler> > HandlerMapType;

class Server
{

public:


	int Initialize(const char* ip, const char* portNo);

	// we'll see about other constructors

	int Execute();

	static Server* GetInstance() { if(mServer == NULL) mServer = new Server; return mServer; }

	static void Destroy() { if(mServer) delete mServer; }

	// Here are the handlers
	int HandleError(int sockFD);

private:

	// private constructor for singleton
	Server() {}

/*	void UpdateMaxFd();
	void KillClient(int sockFD);
*/	
	int mMainFD;
	fd_set mConnectedFDS;
	int mMaxFD;
	
	char mMsgBuf[MSG_BUF_SIZE];

	HandlerMapType mClientMap;

	static Server* mServer;

};

#endif //SERVER_H
